package pro.lingwu.station.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pro.lingwu.station.dto.db.Station;
import pro.lingwu.station.service.StationService;

import javax.validation.Valid;

/**
 * @author @lingwu
 * @date created in 2021/11/16
 */
@Api(tags = "station")
@RestController
public class StationController {

    private final StationService stationService;

    public StationController(StationService stationService) {
        this.stationService = stationService;
    }

    @ApiOperation(value = "增加一个车站")
    @PostMapping("/station")
    ResponseEntity<?> addStation(@RequestBody @Valid Station station){
        stationService.addStation(station);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "获取所有车站")
    @GetMapping("/station")
    ResponseEntity<?> getStations(int start, int size){
        return ResponseEntity.ok(stationService.getAllStations(start, size));
    }

    @Deprecated
    @ApiOperation(value = "获取某个车站的详情")
    @GetMapping("/station/{id}")
    ResponseEntity<?> getStation(@PathVariable long id){
        return ResponseEntity.ok(stationService.findStationById(id));
    }

    @ApiOperation(value = "删除一个车站")
    @DeleteMapping("/station/{id}")
    ResponseEntity<?> rmStation(@PathVariable long id){
        stationService.rmStation(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "更新车站信息")
    @PutMapping("/station/{id}")
    ResponseEntity<?> updateStation(@PathVariable long id, @RequestBody Station station){
        station.setId(id);
        stationService.updateStation(station);
        return ResponseEntity.ok("ok");
    }

}
